package Controller.Actions.Search;

import Controller.*;
import java.io.*;
import java.net.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import Model.Beans.Results.*;
import Model.Beans.*;
import Model.QBE.*;

public class SearchProfessorScheduleAction implements Action {
    
    private String name;
    
    public SearchProfessorScheduleAction() 
    {
        this.name= "SearchProfessorSchedule";
    }
    
    public String getName()
    {
        return name;
    }
    
    public void perform(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException
    {
        response.setContentType("text/xml");
        response.setHeader("Cache-Control", "no-cache");
        String id = request.getParameter("professor_id");
        
        CourseModel cmodel = new CourseModel();
        ProfessorModel pmodel = new ProfessorModel();
        
        Professor_Course result = new Professor_Course();
        
        result.setProfessor(pmodel.search_by_id(id));
        
        CourseList list = new CourseList();
        Person tmp = new Person();
        tmp.setId(Integer.parseInt(id));
        Course course = new Course();
        
        course.setProfessor(tmp);
        
        list = cmodel.search(course);
        
        result.setCourses(list.getCourses());
        if(result != null)
            response.getWriter().write(result.toXML());
    }
}
